package com.lanou3g.code0418.control;

import java.util.concurrent.ForkJoinPool;

/**
 * Created by dllo on 18/4/18.
 */
public class Test03 {
    public static void main(String[] args) {

        long start = System.currentTimeMillis();
        addWithJoin(100000000L);
        //addWithNormal(100000000L);
        long mid = System.currentTimeMillis();
        System.out.println("消耗时间：" + (mid - start) + "ms");

    }


    public static void addWithJoin(long target){

        SumTask task = new SumTask(0L,target);
        //专门用开启动模型的，启动Task的
        ForkJoinPool forkJoinPool = new ForkJoinPool(); // 不写参数，默认看电脑的CPU

        long result =  forkJoinPool.invoke(task); //启动任务，并得到结果 不需要返回值使用excute()
        System.out.println("结果是："+result);

    }


    public static void addWithNormal(Long target){
        long sum = 0;
        for (long i = 0; i <= target;i++){
            sum += i;
        }

        System.out.println("Normal :" + sum);

    }

}
